package com.hymall.controller;

import com.hymall.bean.vo.NoDataResp;
import com.hymall.exception.UnLoginException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author: 叶熠彬
 * @description:
 * @date: 2022/7/21 23:44
 */
@RestControllerAdvice
public class ExceptionController {

    /**
     * 未登录异常处理程序
     *
     * @author: 叶熠彬
     * @date: 2022/7/21 23:48
     * @param: [exception]
     * @return: com.hymall.bean.vo.NoDataResp
     */
    @ExceptionHandler(UnLoginException.class)
    @ResponseBody
    public NoDataResp nullPointExceptionHandler(UnLoginException exception) {
        System.out.println(exception.getMessage());
        NoDataResp noDataRespVO = new NoDataResp();
        noDataRespVO.setErrno(501);
        noDataRespVO.setErrmsg("未登录");
        return noDataRespVO;
    }

    /**
     * @author: 叶熠彬
     * @date: 2022/7/22 9:17
     * @param: [exception]
     * @return: com.hymall.bean.vo.NoDataResp
     */
    @ExceptionHandler(AuthorizationException.class)
    @ResponseBody
    public NoDataResp nullPointExceptionHandler(AuthorizationException exception) {
        System.out.println(exception.getMessage());
        NoDataResp noDataRespVO = new NoDataResp();
        noDataRespVO.setErrno(506);
        noDataRespVO.setErrmsg("没有操作权限！");
        return noDataRespVO;
    }

}
